function preloadImage(src) {
    return new Promise((resolve, reject) => {
        const img = new Image();
        img.onload = () => resolve(img);
        img.onerror = () => reject(new Error(`图片加载失败: ${src}`));
        img.src = src;
    });
}

// 使用
Promise.all([
    preloadImage('image1.jpg'),
    preloadImage('image2.jpg'),
    preloadImage('image3.jpg')
])
    .then(images => {
        console.log('所有图片加载完成');
        images.forEach(img => document.body.appendChild(img));
    })
    .catch(error => {
        console.error('图片加载失败:', error);
    });